package kuoge.practice.concurrent.vert;

import io.vertx.core.*;

import java.util.concurrent.TimeUnit;

public class VerticleTest extends AbstractVerticle {
    @Override
    public void init(Vertx vertx, Context context) {
        super.init(vertx, context);
        System.out.print("init~");
    }

    @Override
    public void start(Promise<Void> startPromise) throws Exception {
        super.start(startPromise);
        vertx.eventBus().localConsumer("test")
                .bodyStream().handler(m -> {
                    System.out.println("data:" + m);
                });
    }

    @Override
    public void stop(Promise<Void> stopPromise) throws Exception {
        super.stop(stopPromise);
    }
    public static void main(String[] args) {
        final VertxOptions vertxOptions = new VertxOptions();
        vertxOptions.setBlockedThreadCheckIntervalUnit(TimeUnit.DAYS);
        final Vertx vertx = Vertx.vertx(vertxOptions);
        final VerticleTest verticle = new VerticleTest();
        final Future<String> future = vertx.deployVerticle(verticle);
        future.onComplete(result -> {
            if (result.succeeded()) {
                final String dId = result.result();
                System.out.println("future succeeded~:" + dId);
                vertx.eventBus().publish("test", "hello eventBus");
            }else {
                System.out.println("failed:" + result.cause().getMessage());
            }
        });
        System.out.println("end");
    }
}
